package cn.edu.xjtu.tencent.formal;

/**
 * @author Hydrion-QLz
 * @date 2022-09-13 20:29
 * @description
 */
public class first {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param a ListNode类一维数组 指向这些数链的开头
     * @return ListNode类
     */
    public ListNode solve(ListNode[] a) {
        // write code here
        ListNode head = new ListNode(0);
        ListNode temp = head;
        while (true) {
            boolean flag = true;
            for (int i = 0; i < a.length; i++) {
                ListNode node = a[i];
                if (node != null) {
                    temp.next = new ListNode(node.val);
                    temp = temp.next;
                    a[i] = node.next;
                    flag = false;
                }
            }
            if (flag) {
                break;
            }
        }
        return head.next;
    }
}

class ListNode {
    int val;
    ListNode next = null;

    public ListNode(int val) {
        this.val = val;
    }
}